package cn.gson.springboot.controllers;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.gson.springboot.model.mapper.MlossMapper;
import cn.gson.springboot.model.pojos.MedicalCardPx;
import cn.gson.springboot.model.pojos.User;
import cn.gson.springboot.model.service.Ghlxserivce;
import cn.gson.springboot.model.service.MedicalService;
@Controller
public class MedicalController {
	@Autowired
	private MedicalService ms;
	
	@Autowired
	private Ghlxserivce  gs;
	
	//诊疗卡界面
	@RequestMapping("zhenliaoka")
	public void zhenLiaoKa(){	
		
	}
	//统计报表界面
	@RequestMapping("bao-biao")
	public void baoBiao(Model modle){	
	}
	
	//新增门诊
	@RequestMapping("mz-xz")
	public void mzXz(Model modle){	
	}	
	
	//所有医疗卡数据源
	@RequestMapping("yiliaok")
	@ResponseBody
	public Map<String,Object> hosLikeTableSmt(
			@RequestParam("page")int page,
			@RequestParam("rows")int rows){
		//进行分页
		Page<Object> pg = PageHelper.startPage(page,rows);
		JSONArray finall=ms.finall();
		
		//进行数据格式转换和封装
		Map<String,Object> map = new HashMap<>();
		map.put("total", pg.getTotal());//封装总记录数
		map.put("rows", finall);//封装当前页的内容
		return map;
	}
	
	//<!-- 查询正常使用的医疗卡 -->
	@RequestMapping("zcyiliaok")
	@ResponseBody
	public Map<String,Object> zhenchang(
				@RequestParam("page")int page,
				@RequestParam("rows")int rows){
			//进行分页
			Page<Object> pg = PageHelper.startPage(page, rows);
		
				JSONArray canfindAll = ms.canfindAll();
			
			//进行数据格式转换和封装
			Map<String,Object> map = new HashMap<>();
			map.put("total", pg.getTotal());//封装总记录数
			map.put("rows", canfindAll);//封装当前页的内容
			
			return map;
	}
	
		
	//修改医疗卡的使用状态===挂失
	@PostMapping("xiugaika")
	@ResponseBody
	public String guaShi(Integer mzcardId,HttpSession session){
			try {
				User user = (User)session.getAttribute("user");
				String userName = user.getUserName();
				ms.guaShi(mzcardId,userName);
				return "1";
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
				return "0";
			}
		}
	
		//所有挂失记录表格数据源
		@RequestMapping("guashi")
		@ResponseBody
		public Map<String,Object>mloss(
				@RequestParam("page")int page,
				@RequestParam("rows")int rows){
			//进行分页
			Page<Object> pg = PageHelper.startPage(page, rows);
				JSONArray finloss = ms.finloss();
				
						//进行数据格式转换和封装
			Map<String,Object> map = new HashMap<>();
			map.put("total", pg.getTotal());//封装总记录数
			map.put("rows", finloss);//封装当前页的内容
			
			return map;
		}
		
		//医疗卡补办事件
		@PostMapping("buban")
		@ResponseBody
		public String buban(Integer mzcardId,HttpSession session) {
			try {
				User user = (User)session.getAttribute("user");
				String userName = user.getUserName();
				String buban = ms.buban(mzcardId,userName);
				return buban;
				
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
				return "0";
			}
			
		}
		
		//所有补办记录表格数据源
		@RequestMapping("findreplace")
		@ResponseBody
		public Map<String,Object>findreplace(
						@RequestParam("page")int page,
						@RequestParam("rows")int rows){
				//进行分页
				Page<Object> pg = PageHelper.startPage(page, rows);
				JSONArray finloss =ms.findreplace();
				
				//进行数据格式转换和封装
				Map<String,Object> map = new HashMap<>();
				map.put("total", pg.getTotal());//封装总记录数
				map.put("rows", finloss);//封装当前页的内容
					
				return map;
		}
	
	
		//医疗卡新增方法
		@PostMapping("medicl")
		@ResponseBody
		public String addmedical(MedicalCardPx m,HttpSession session) {
			try {
						JSONArray sfzsy = ms.sfzsy(m.getCardCid());
						if(sfzsy.size()<=0) {
							User user = (User)session.getAttribute("user");
							String userName = user.getUserName();	
							ms.addmedical(m,userName);
							return "1";
						}else {
							return "2";
						}
						
				
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
				return "0";
			}
			
		}
		
		
		
		
		 //<根据医疗卡卡号查询病人挂号信息> -->
		@PostMapping("idcgh")
		@ResponseBody
		public  JSONArray  idcgh(String mecard_number) {
			JSONArray idcgh = ms.idcgh(mecard_number);
			System.out.println(idcgh);
			return idcgh;
		}
		//医疗卡号查询医疗卡信息
		@PostMapping("findid")
		@ResponseBody
		public JSONArray findid(String mecard_number){
				JSONArray findid =ms.findid(mecard_number);
				System.out.println(findid);
				return findid;
		};
		
		
		//根据医疗卡查询挂号记录
		@PostMapping("cardghjl")
		@ResponseBody
		public JSONArray cardghjl(String mecard_number) {
			
			JSONArray cardghjl =ms.cardghjl(mecard_number);
			return cardghjl;
		}
		
		//<!-- 根据医疗卡编号查询补办记录 -->
		@PostMapping("bbjl")
		@ResponseBody
		public JSONArray bbjl(String mecard_number) {
			JSONArray bbjl =ms.bbjl(mecard_number);
			return bbjl;
		}
		
		//根据医疗卡卡号查询用户信息未挂失的医疗卡
		@PostMapping("idmedical")
		@ResponseBody
		public JSONArray idmedical(String mecard_number) {
			
			JSONArray idmedical = ms.idmedical(mecard_number);
			return idmedical;
		}
		
		//<!--根据身份证查询正常使用的医疗卡  -->
		@PostMapping("sfzcx")
		@ResponseBody
		public JSONArray sfzcx(String card_cid) {
			JSONArray sfzcx = ms.sfzcx(card_cid);
			return sfzcx;
		}
		//<!--根据身份证查询医疗卡  -->
		@PostMapping("sfzsy")
		@ResponseBody
		public JSONArray sfzsy(String card_cid) {
			JSONArray sfzsy = ms.sfzsy(card_cid);
			return sfzsy;
		}
	
	
}
